<template> 
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>发货</span>
    </el-card>
    <div class="table-container">
      <el-table ref="deliverOrderTable"
                style="width: 100%;"
                :data="list" border>
        <el-table-column label="订单编号" width="180" align="center">
          <template slot-scope="scope">{{scope.row.orderId}}</template>
        </el-table-column>
        <el-table-column label="收货人" width="180" align="center">
          <template slot-scope="scope">{{scope.row.receiver}}</template>
        </el-table-column>
        <el-table-column label="手机号码" width="160" align="center">
          <template slot-scope="scope">{{scope.row.receiverMobile}}</template>
        </el-table-column>
        <el-table-column label="邮政编码" width="160" align="center">
          <template slot-scope="scope">{{scope.row.receiverZip}}</template>
        </el-table-column>
        <el-table-column label="收货地址" align="center">
          <template slot-scope="scope">{{scope.row.receiverAddress}}</template>
        </el-table-column>
        <el-table-column label="配送方式" width="160" align="center">
          <template slot-scope="scope">
            <el-select placeholder="请选择物流公司"
                       v-model="shippingName"
                       size="small">
              <el-option v-for="item in companyOptions"
                         :key="item"
                         :label="item"
                         :value="item">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="物流单号" width="180" align="center">
          <template slot-scope="scope">
            <el-input size="small" v-model="shippingCode"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top: 15px;text-align: center">
        <el-button @click="goShip">取消</el-button>
        <el-button @click="updateShip" type="primary">确定</el-button>
      </div>
    </div>
  </div>
</template>
<script>
  const defaultLogisticsCompanies=["顺丰快递","圆通快递","中通快递","韵达快递"];
  export default {
    name: 'deliverOrderList',
    props:['currentId'],
    data() {
      return {
        list:[],
        companyOptions:defaultLogisticsCompanies,
        shippingCode:'',
        shippingName:''
      }
    },
    // created(){
    //   this.list= this.$route.query.list;
    //   //当list不为数组时转换为数组
    //   if(this.list instanceof Array===false){
    //     this.list=[];
    //   }
    // },
    methods:{
      updateShip(){
        this.$http.post("/order/order/updateShip",{
          orderNum:this.currentId,
          shippingName:this.shippingName,
          shippingCode:this.shippingCode
        }).then(res=>{
          if (res.data.data===true){
            this.$message.success("更新物流成功！")
            this.$emit('goShip')
          }else {
            this.$message.error("更新失败！")
          }
          this.getOrderList()
        })
      },
      goShip(){
        this.$emit('goShip')
      },
      cancel(){
        this.$router.back();
      },
      confirm(){
        this.$confirm('是否要进行发货操作?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deliveryOrder(this.list).then(response=>{
            this.$router.back();
            this.$message({
              type: 'success',
              message: '发货成功!'
            });
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消发货'
          });
        });
      }
    },
    created() {
      this.$http.get("/order/order/"+this.currentId).then(res=>{
        this.list.push(res.data.data)
      })
    }
  }
</script>
<style></style>


